package algorithm.annotation_demo;

import java.lang.reflect.Field;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        User user = new User();
        Class c = user.getClass();
        //反射注解
        Field[] f = c.getDeclaredFields();
        /*for (Field field:f){
            field.setAccessible(true);
            MyColumn myColumn = field.getAnnotation(MyColumn.class);
            if (myColumn != null) {
                System.out.println("注解名："+myColumn.type()+"|"+myColumn.value()+"|"+myColumn.constraint().toString()+myColumn.annotationType());
                System.out.println(field.getName());
            } else {
                System.out.println("没有注解");
            }
        }*/

        Arrays.asList(f).forEach(
                field -> {
                    field.setAccessible(true);
                    MyColumn myColumn = field.getAnnotation(MyColumn.class);
                    if (myColumn != null) {
                        System.out.println("注解名："+myColumn.type()+"|"+myColumn.value()+"|"+myColumn.constraint().toString()+myColumn.annotationType());
                        System.out.println(field.getName());
                    } else {
                        System.out.println("没有注解");
                    }
                }
        );

    }
}
